#if defined(ARCH_ARM) && defined(__ARM_FEATURE_SVE)
#include <arm_sve.h>
#include "../../core.h"

// SVE优化的矩阵乘法
ErrorCode matrix_multiply_sve(const Matrix* a, const Matrix* b, Matrix** result) {
    if (!a || !b) return ERR_NULL_PTR;
    if (a->cols != b->rows) return ERR_DIMENSION_MISMATCH;
    
    Matrix* out = matrix_create(a->rows, b->cols);
    if (!out) return ERR_MEMORY_ALLOC;
    
    const size_t vl = svcntd(); // SVE向量长度
    
    for (size_t i = 0; i < a->rows; i++) {
        for (size_t j = 0; j < b->cols; j += vl) {
            svfloat64_t sum = svdup_f64(0.0);
            svbool_t pg = svwhilelt_b64(j, b->cols);
            
            for (size_t k = 0; k < a->cols; k++) {
                svfloat64_t a_val = svdup_f64(a->data[i * a->cols + k]);
                svfloat64_t b_val = svld1(pg, &b->data[k * b->cols + j]);
                sum = svmla_m(pg, sum, a_val, b_val);
            }
            
            svst1(pg, &out->data[i * out->cols + j], sum);
        }
    }
    
    *result = out;
    return SUCCESS;
}
#endif